/**
 * Copyright (C) 2010 Sergey Grigoriev <s.a.grigoriev@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.gmf.core

import com.google.inject.Module
import com.google.inject.Binder
import org.apache.log4j.Logger
import com.google.inject.Scopes
import com.google.inject.name.Names
import net.gmf.dsl.FlexProject
import org.apache.maven.artifact.repository.ArtifactRepository
import org.apache.maven.artifact.resolver.ArtifactResolver
import org.apache.maven.artifact.handler.ArtifactHandler


class CoreModule implements Module {
  private Logger logger
  private Set attachedArtifacts
  private final ArtifactHandler swfArtifactHandler
  private final ArtifactHandler swcArtifactHandler
  private final ArtifactResolver artifactResolver
  private final ArtifactRepository localRepository
  private List<ArtifactRepository> remoteRepositories

  CoreModule(Logger logger,
             Set attachedArtifacts,
             ArtifactHandler swfArtifactHandler,
             ArtifactHandler swcArtifactHandler,
             ArtifactResolver resolver,
             ArtifactRepository localRepository,
             List<ArtifactRepository> remoteRepositories
  ) {
    this.logger = logger;
    this.attachedArtifacts = attachedArtifacts
    this.swfArtifactHandler = swfArtifactHandler
    this.swcArtifactHandler = swcArtifactHandler
    this.artifactResolver = resolver
    this.localRepository = localRepository
    this.remoteRepositories = remoteRepositories
  }

  void configure(Binder binder) {
    binder.bind(Logger).toInstance(logger)
    binder.bind(FlexSdkFacade).in(Scopes.SINGLETON)
    binder.bind(Set).annotatedWith(Names.named('attachedArtifacts')).toInstance(attachedArtifacts)
    binder.bind(ArtifactHandler).annotatedWith(Names.named('swfArtifactHandler')).toInstance(swfArtifactHandler)
    binder.bind(ArtifactHandler).annotatedWith(Names.named('swcArtifactHandler')).toInstance(swcArtifactHandler)
    binder.bind(ArtifactResolver).toInstance(artifactResolver)
    binder.bind(ArtifactRepository).toInstance(localRepository)
    binder.bind(List).annotatedWith(Names.named('remoteRepositories')).toInstance(remoteRepositories)
  }
}
